﻿@{ Layout = "~/Views/Shared/_leftPanelLayout.cshtml";}
@section LeftTree
{
     
    @{
        Html.RenderPartial("DeptTreePartialView", new Webcar.Models.DeptTreeMode { Action = "List", Controller = "Car", ShowChild = true });
     }
}
@using (Html.BeginForm("Save", "Photo", Html.ViewContext.RouteData.Values, FormMethod.Post, new { enctype = "multipart/form-data" }))
{
    @Html.Hidden("id",Html.ViewContext.RouteData.Values["id"])
    <div style="padding-bottom:5px;padding-top:5px" class="div-blue">
        上传新照片(小于 4096KB , 可用扩展名: jpg, jpeg, gif, bmp)
        <hr />
        <table>
            <tr>
                <td>照片描述：@Html.TextBox("PhotoName", "", new {style="width:300px" })</td>
                <td><input type="file" id="fileImage" name="fileImage" /> </td>
                <td>
                    @Html.DevExpress().Button(settings =>
                    {
                        settings.Name = "Button1";
                        settings.Text = "上传";
                        settings.UseSubmitBehavior = false;
                        settings.Width = 70;
                        settings.ControlStyle.CssClass = "button1";
                        settings.ClientSideEvents.Click = "function(s, e){ commit_data();}";
                    }).GetHtml()
                </td>

            </tr>
        </table>
    
    </div>
}
<br />
<div id="list-car">
    @Html.DevExpress().DataView(
    settings => {
        settings.Name = "dataView";
        //settings.CallbackRouteValues = new { Controller = "DataView", Action = "DataBindingPartial" };
        settings.SettingsTableLayout.ColumnCount = 3;
        settings.Width = Unit.Percentage(100);
        settings.AllowPaging = false;
        //settings.PagerAlign = DevExpress.Web.ASPxDataView.PagerAlign.Justify;
        
        settings.SetItemTemplateContent( 
            c => {
                string url = DataBinder.Eval(c.DataItem, "PhotoUrl").ToString();
                string image_urll = Url.Action("ShowSmall", "Photo", new { id = url });
                string image_url_large = Url.Action("ShowLarge", "Photo", new { id = url });
                string del_url = Url.Action("Delete", "Photo", new { id = url, photo_type = Html.ViewContext.RouteData.Values["photo_type"], pkid = Html.ViewContext.RouteData.Values["id"] });
                string name = DataBinder.Eval(c.DataItem, "Name").ToSafeString();
                ViewContext.Writer.Write(
                    @"<table>
                        <tr>
                            <td colspan='3'>
                                <a href='{2}' target='_blank'><img src='{0}' /></a>
                            </td>
                        </tr>
                        <tr>
                            <td><b>照片名称:</b></td>
                            <td><span>{1}</span></td>
                            <td><a href='{3}' onclick='{4}'>[删除照片]</a></td>
                        </tr>
                    </table>".FormatWith(image_urll, name, image_url_large, del_url,"return confirm(\"是否要删除此照片？\")")
                );
            }
        );
    }
    ).Bind(Model).GetHtml()
</div>

<script type="text/javascript">
    function commit_data() {
        var file = $("#fileImage").val();
        if (file == null || file == "") {
            alert("请选择要上传的文件。");
            return;
        }
        var allow_ext = "jpg|jpeg|gif|bmp|";
        if (!check_file("fileImage", allow_ext, 4096)) return;
        document.forms[0].submit();
    };
</script>



